﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using System.IO;
using Silverlight.Samples;
using SomethingSpacialClassLib.Web;
using SomethingSpacial.ViewModel;
using SomethingSpacial.Model;
using System.ServiceModel.DomainServices.Client;
using SomethingSpacial.AppServices;

namespace SomethingSpacial.Views.MixItUp
{
    public partial class ViewPresentationRoom : UserControl
    {

        private CaptureSource CapSrc = new CaptureSource();
        private VideoBrush MyVideoBrush = new VideoBrush();
        private WriteableBitmap _bitmap;
        private bool VideoIsPlaying = false;
        private SomethingSpacialContext domainContext = new SomethingSpacialContext();
        LoadOperation LoadLatestEventFeedback;
        LoadOperation LoadLastEventFeedback;
        private int LastFeedbackID = 0;
        private int LastBubble = 0;
        private int EventID = 1;  //replace this with the ID of the selected event
        private string DefaultQuestion = "Enter your question...";
        public ViewPresentationRoom()
        {
            InitializeComponent();
            InitializePage();
        }

        private void InitializePage()
        {
            Loaded += new RoutedEventHandler(RoomEvent_Loaded);
            //controlChatWindow.controlTextBox.textBlockChatEntry.MouseLeftButtonUp += new MouseButtonEventHandler(textBlockChatEntry_MouseLeftButtonUp);

            //GetLastEventFeedbackID();

        }

        void borderSubmit_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            SaveFeedback();
            ResetQuestionBox();
        }

        void textBlockChatEntry_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            SaveFeedback();
            ResetQuestionBox();
         //   controlChatWindow.controlTextBox.textBlockChatEntry.Focus();
            
        }


        public void StartTimer()
        {
          //  System.Windows.Threading.DispatcherTimer myDispatcherTimer = new System.Windows.Threading.DispatcherTimer();
          //  myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 3, 100); // 100 Milliseconds 
          //  myDispatcherTimer.Tick += new EventHandler(GetNextFeedack);
          //  myDispatcherTimer.Start();
        }


        void buttonSendQuestion_Click(object sender, RoutedEventArgs e)
        {
            
            ResetQuestionBox();
 //           commentsTextBoxControl.Focus();
        }

        void SaveFeedback()
        {
            AppServices.Web.User CurrentUser = SomethingSpacial.AppServices.WebContext.Current.User;
            string UserName = CurrentUser.DisplayName;
            string FeedbackType = "question";
            //       if (radioButtonComment.IsChecked == true)
            //       {
            FeedbackType = "comment";
            //       }
            string FeedbackContent = controlChatWindow.controlTextBox.textBoxComment.Text;


            controlChatWindow.SaveFeedback(UserName, FeedbackType, EventID, FeedbackContent);

            ResetQuestionBox();

        }

        void ResetQuestionBox()
        {
   
            controlChatWindow.controlTextBox.textBoxComment.Text = DefaultQuestion;
            controlChatWindow.controlTextBox.textBoxComment.Focus();
            controlChatWindow.controlTextBox.textBoxComment.SelectAll();
        }

        void RoomEvent_Loaded(object sender, RoutedEventArgs e)
        {
       //     ((EventFeedbackViewModel)this.DataContext).loadEventFeedback();

            controlChatWindow.controlTextBox.borderSubmit.MouseLeftButtonUp += new MouseButtonEventHandler(borderSubmit_MouseLeftButtonUp);
            //  buttonSendQuestion.Click += new RoutedEventHandler(buttonSendQuestion_Click);
            ResetQuestionBox();


            //((LocationsViewModel)this.DataContext).loadLocations();
            //((EventFeedbackViewModel)this.DataContext).
            //StartCamBtn.Click += new RoutedEventHandler(StartCamBtn_Click);
            //TakeSnapBtn.Click += new RoutedEventHandler(TakeSnapBtn_Click);
            //SaveSnapBtn.Click += new RoutedEventHandler(SaveSnapBtn_Click);
        }

        
    }
}
